package com.wenterprises.snkeishiki;

import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Field;

/**
 * 
 * @author RafaelSilva
 */
public class App {

    public static final String RESULT = "src/main/resources/sheet.pdf";
    public static final String RESOURCE = "src/main/resources/ficha.jpg";
    public final static short ID = 257;
    public final static short NUM = 258;
    
    
    public static void getFieldName(int num) {
        Class c = App.class;
        Field[] fs = c.getFields();
        for (Field f : fs)
            try {
                short value = f.getShort(null);
                if (value == num)
                    System.out.println(f.getName());
            } catch (Exception ex) {}
        System.exit(0); 
    }
    
    public static void main(String[] args) {
        
        //getFieldName(258);
        
        try {
            System.out.println("SNKeishiki RPG Creator");

            File f = new File(RESOURCE);
            if (f.exists()) {
                System.out.println("Found! " + f.getAbsolutePath());
            } else {
                System.out.println("Not found! " + f.getAbsolutePath());
                System.exit(-1);
            }

            Document document = new Document(PageSize.A4, 0, 0, 0, 0);
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));

            document.open();
            Paragraph p = new Paragraph("Nome do Personagem", new Font(FontFamily.HELVETICA, 18));
            p.setAlignment(Element.ALIGN_CENTER);
            document.add(p);

            // Create and add an Image
            Image img = Image.getInstance(RESOURCE);
            img.setAbsolutePosition(
                    (PageSize.A4.getWidth() - img.getScaledWidth()) / 2,
                    (PageSize.A4.getHeight() - img.getScaledHeight()) / 2);
            document.add(img);

            document.close();
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
